---
title: "context.headers / context.setHeader()"
description: Access request headers and set response headers.
---

---

<Warning>
This API can only be used on the server and is only available using the `package:jaspr/server.dart` import.
</Warning>

## context.headers

With the `context.headers` and `context.headersAll` getters you can access the HTTP headers of the currently handled request on the server.

```dart
class MyComponent extends StatelessComponent {
  @override
  Component build(BuildContext context) {
    final userAgent = context.headers['user-agent'];
    return p([text('User-Agent: $userAgent')]);
  }
}
```

## context.setHeader()

The `context.setHeader(String name, String value)` method lets you set a response header for the current request.

```dart
class MyComponent extends StatelessComponent {
  @override
  Component build(BuildContext context) {
    context.setHeader('X-Rendered-By', 'Jaspr');

    return p([text('Hello, World!')]);
  }
}
```